package top.bigdata.config;

import lombok.extern.log4j.Log4j2;
import org.apache.hive.service.cli.HiveSQLException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import top.bigdata.model.dto.Response;

import java.net.ConnectException;

@RestControllerAdvice
@Log4j2
public class GlobalExceptionHandler {
    @ExceptionHandler(ConnectException.class)
    public Response<String> handleConnectException(ConnectException e) {
        log.error(e.getMessage());
        return Response.error("服务器异常：无法连接到数据库");
    }

    @ExceptionHandler(HiveSQLException.class)
    public Response<String> handleHiveSQLException(HiveSQLException e) {
        log.error(e.getMessage());
        return Response.error("服务器异常：SQL异常");
    }
}
